package com.gitee.bodboy.result;

import com.gitee.bodboy.constant.ResEnum;
import lombok.Data;

/**
 * @ClassName CommonResult
 * @Description TODO
 * @Author xiongchao
 * @Date 2020/12/11 9:32
 **/
@Data
public class CommonResult<T> {
    private String msg;

    private Integer code;

    private T data;

    public CommonResult(){

    }

    public CommonResult(String msg, Integer code, T data) {
        this.msg = msg;
        this.code = code;
        this.data = data;
    }

    public CommonResult(String msg, T data) {
        this.msg = msg;
        this.data = data;
    }

    public static <T> CommonResult<T> ok (T data, Integer code, String msg){
        return new CommonResult<>(ResEnum.SUCCESS.getMsg(), ResEnum.SUCCESS.getCode() ,data);
    }

    public static <T> CommonResult<T> error(Integer code, String msg){
        return new CommonResult<>(ResEnum.FAILED.getMsg(),ResEnum.FAILED.getCode(),null);
    }
}
